
const fs = require('fs');
const path = require('path');
const axios = require('axios');

let i = 0;
/*
let url = process.argv[2]
  ? `http://192.168.5.44:8868/${process.argv[2]}/zxwms`
  : 'http://192.168.5.44:8868/zxwms';
console.log('update URL:  ' + url);
*/
let url = process.argv[2]
  ? `http://192.168.5.244:8868/${process.argv[2]}/zxwms`
  : 'http://192.168.5.244:8868/zxwms';
console.log('update URL:  ' + url);
try {
  (async function () {
    let {data} = await axios.post(url, {password: 'H@5d!J*t5!DS55221!5DF4QqL'});
    fs.writeFile(path.resolve(__dirname, './client/config/config.json'), JSON.stringify(data), err => {
      if (err) {
        throw err;
      }
      if (++i === 2) {
        console.log('\n\t\tConfig Update Success!\n');
      }
    });
    fs.writeFile(path.resolve(__dirname, './server/config/config.json'), JSON.stringify(data), err => {
      if (err) {
        throw err;
      }
      if (++i === 2) {
        console.log('\n\t\tConfig Update Success!\n');
      }
    });
  })();
} catch (err) {
  console.error(err);
}
